package cn.edu.zafu.bigdata.x.huangxihao202211080211;

class Cube {
    private double length;
    private double width;
    private double height;

    // 带参构造方法
    public Cube(double length, double width, double height) {
        this.length = length;
        this.width = width;
        this.height = height;
    }

    // 获取长
    public double getLength() {
        return length;
    }

    // 获取宽
    public double getWidth() {
        return width;
    }

    // 获取高
    public double getHeight() {
        return height;
    }

    // 重写equals方法
    @Override
    public boolean equals(Object obj) {
        // 判断是否为同一对象
        if (this == obj) {
            return true;
        }
        // 判断是否为空或类型不同
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        Cube other = (Cube) obj;
        // 判断长、宽、高是否都相等
        return Double.compare(length, other.length) == 0 &&
                Double.compare(width, other.width) == 0 &&
                Double.compare(height, other.height) == 0;
    }
}

public class Cube11 {
    public static void main(String[] args) {
        // 创建Cube对象
        Cube cube1 = new Cube(2.0, 3.0, 4.0);
        Cube cube2 = new Cube(2.0, 3.0, 4.0);
        Cube cube3 = new Cube(1.0, 2.0, 3.0);

        // 测试相等性
        System.out.println("cube1.equals(cube2): " + cube1.equals(cube2)); // true
        System.out.println("cube1.equals(cube3): " + cube1.equals(cube3)); // false

        // 测试相等性与自身比较
        System.out.println("cube1.equals(cube1): " + cube1.equals(cube1)); // true
    }
}

